package com.observer.demo1.impl;

import com.observer.demo1.face.DisplayElement;
import com.observer.demo1.face.Observer;
import com.observer.demo1.face.Subject;

public class CurrentConditionsDisplay implements Observer, DisplayElement {

	private float temperature;
	private float humidity;
	// 为什 么要 保 存 对Subject的引用呢？构造完后似乎用不着了呀？
	// 的确如此，但是以后我们可能想要取消注册，如果已经有了对Subject的引用会比较方便。
	@SuppressWarnings("unused")
	private Subject weatherData;

	public CurrentConditionsDisplay(Subject weatherData) {
		this.weatherData = weatherData;
		weatherData.registerObserver(this);
	}

	@Override
	public void display() {
		// TODO Auto-generated method stub
		System.out.println("Current conditions: " + temperature
				+ "F degrees and " + humidity + "% humidity");
	}

	@Override
	public void update(float temperature, float humidity, float pressure) {
		// TODO Auto-generated method stub
		this.temperature = temperature;
		this.humidity = humidity;
		display();
	}

}
